﻿using FirstFloor.ModernUI.Presentation;
using FirstFloor.ModernUI.Windows.Controls;
using FirstFloor.ModernUI.Windows.Navigation;
using LinnerToolkit.Desktop.ModernUI.Mvvm;
using LinnerToolkit.Desktop.ModernUI.Navigation;
using SimulationPTSystem.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace SimulationPTSystem.ViewModels
{
    public class LoginPageViewModel : ModernViewModelBase
    {
        private string userName;
        private string password;

        public string UserName { get => userName; set => Set(ref userName, value); }

        public string Password { get => password; set => Set(ref password, value); }

        public ICommand LoginCommand { get; }
        public LoginPageViewModel(IModernNavigationService navigationService) : base(navigationService)
        {
            LoginCommand = new RelayCommand((obj) =>
              {
                  if(string.IsNullOrEmpty(UserName)||string.IsNullOrEmpty(Password))
                  {
                      ModernDialog.ShowMessage("用户名和密码不能为空", string.Empty, System.Windows.MessageBoxButton.OK);
                      return;
                  }

                  if (SimulationPTDAL.Login(UserName, Password))
                      navigationService.NavigateTo("MainPage");
              });
        }

        public override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
        }
    }
}
